<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/login/regist.css" />
    <style>
    	body{
    		
    	}
    </style>
</head>
<body class="login">

	<div class="infoTop">
		<a onClick="javascript :api.closeFrame();"><img alt="返回" src="" title="back"></a> 
		<span>用户注册</span>
	</div>
	
		<div class="content">
			<div class="login-box">
				<div class="login-phonenumber">
					<input   id="userName" type="text" name="userName" placeholder="请输入用户名" maxlength="11" autocomplete="off"/>
				    <span id="message" ></span>
				</div>
		
				<div class="login-password">
					<input id="passWord" type="password" name="password" value="" placeholder="请设置初始密码" maxlength="20"/>
					<span id="pmsg"></span>
				</div>
				
				<div class="login-repassword">
					<input id="confirmPassword" type="password" name="confirmPassword" placeholder="请确认初始密码" maxlength="20"/>
					<span id="cpmsg"></span>
				</div>
			</div>
			<div class="login-rememberme">
				<!-- <input name="" type="checkbox" id="check" value="" /><label for="check">我已看过并同意<a onclick="readAgreenment();">《用户服务协议》</a> </label> -->
				<input type="radio" id="role" name="role" value="现场工人" /><span>现场工人</span>
                <input type="radio" id="role" name="role" value="库管员" /><span>库管员</span>
                <input type="radio" id="role" name="role" value="部门领导" /><span>部门主管</span>
			    <span id="ramsg"></span>
			</div>
			<div class="login-select" id="select1">
				 <select id="makerid" name="makerid">
	                <!-- <option value="">请选择所属部门</option>
	                <option value="合格">合格</option>
	                <option value="返修">返修</option>
	                <option value="报废">报废</option> -->
	            </select>
	            <span>请选择所属部门</span>
            </div>
            <div class="login-select1" id="select2">
				 <select id="houseid" name="houseid">
	                <!-- <option value="">请选择所管仓库</option>
	                <option value="合格">合格</option>
	                <option value="返修">返修</option>
	                <option value="报废">报废</option> -->
	            </select>
	            <span>请选择所管仓库</span>
            </div>
			<div class="login-btn">
				<button id="registerBtn" type="submit" >注&nbsp;册</button>
			</div>
		</div>
	
</body>
<script type="text/javascript" src="../script/public/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/core/core.js"></script>
<script type="text/javascript">
	apiready = function(){
	$makerid = $api.byId('makerid');//领料部门
			$houseid = $api.byId('houseid');//仓库id
	ajaxLocal({flag:'0'},'user','listWarehouseAndDepart',function(ret,err){
			     //alert("验证成功!!"+JSON.stringify(err));
			     //alert("验证成功!!"+JSON.stringify(ret));
			     markerHtml = '<option value="">请选择所属部门</option>';
				 houseHtml = '<option value="">请选择所管仓库</option>';
			if(ret.listD.length!=0){	 
				for(i = 0; i < ret.listD.length; i++){
//					if(ret.listD[i][1]=='南车库'){
//					 markerHtml+='<option value="'+ret.listD[i][1]+'" selected="selected">'+ret.listD[i][1]+'</option>'
//					}else{
					markerHtml+='<option value="'+ret.listD[i][0]+'-'+ret.listD[i][1]+'">'+ret.listD[i][0]+ret.listD[i][1]+'</option>'
					//}
				}
			}	
				for(i = 0; i < ret.listW.length; i++){
					
					 houseHtml+='<option value="'+ret.listW[i][0]+'-'+ret.listW[i][1]+'">'+ret.listW[i][0]+ret.listW[i][1]+'</option>'
					
				}
				$api.html($makerid, markerHtml);
				$api.html($houseid, houseHtml);
							
	    });
	
	
	
	$('input[name="role"]').change(function() {
        if (this.value == '现场工人'||this.value == '部门领导') {
            //alert("库管员");
            document.getElementById("select2").style.display = "none";
        }else{
        	document.getElementById("select2").style.display = "block";
        }
        
    });
			$("#registerBtn").click(function(){
		 	
			var username=$("#userName").val();
			var pass=$("#passWord").val();
			var repass=$("#confirmPassword").val();
			var role=$('input[name="role"]:checked').val();
			var depart=$("#makerid").val();
			var house=$("#houseid").val();
			//alert(role);
			if (username==''||username==undefined||username==null) 
			{
				$("#message").html("请输入账号！");
				//alert('请输入账号！！');
				return false;
			}
			else if (username.length<2) 
			{
			    
    			$("#message").html("用户名不能小于2位！");
    			//alert('请输入密码！！');
				return false;
			}
        	else if (pass==''||pass==undefined||pass==null) 
			{
			    
    			$("#pmsg").html("请输入密码！");
    			//alert('请输入密码！！');
				return false;
			}else if(pass!=repass){
			  $("#cpmsg").html("密码不一致！");
			  //alert("密码不一致！");
			  return false;
			}else if(role==undefined){
			   $("#ramsg").html("请选择用户类型！");
			   return false;
			}
			else if(depart==''||depart==undefined||depart==null){
			   alert("请选择所属部门！");
			   return false;
			}
			else{
			 //alert("验证成功");
			 if(role=="库管员"){
				 if(house==''||house==undefined||house==null){
				   alert("请选择所管仓库！");
				   return false;
				}else{
						ajaxLocal({userName:username,password:pass,role:role,depart:depart,house:house},'user','addUserApp',function(ret,err){
						//alert("验证成功!!"+JSON.stringify(ret));
						if(ret.success){
							//注册成功,打开登录页面
							//alert("成功");
							api.closeFrame({
								name:'register'
	                        });
			    			api.openWin({
		                        name: 'login',
		                        url: 'login.html'
	                        });
			    			
					    }else{
					   		$("#message").html(ret.message);
							//return false;
					    }
					});
				}
			 }else{
				ajaxLocal({userName:username,password:pass,role:role,depart:depart,house:house},'user','addUserApp',function(ret,err){
					//alert("验证成功!!"+JSON.stringify(ret));
					if(ret.success){
						//注册成功,打开登录页面
						//alert("成功");
						api.closeFrame({
							name:'register'
                        });
		    			api.openWin({
	                        name: 'login',
	                        url: 'login.html'
                        });
		    			
				    }else{
				   		$("#message").html(ret.message);
						//return false;
				    }
				});
			 }
			}
		});
	};
</script>
</html>